package com.itfreer.demo.form;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.itfreer.bpm.model.BpmBaseEntity;
import com.itfreer.form.api.reflect.DictionaryField;
import com.itfreer.utils.file.FileMeta;
import com.itfreer.utils.json.JsonUtils;

/**
 * 简单表单示例
 */
@Entity(name = "demo_form_simple")
public class SimpleFormEntity extends BpmBaseEntity implements Serializable {

	private static final long serialVersionUID = -1267481776516760706L;

	/**
	 * 帐号 唯一值
	 */
	@Id
	@Column(name = "id", length = 50, nullable = false)
	private String id;

	/**
	 * 帐号
	 */
	@Column(name = "s_accounts", length = 50, nullable = false)
	private String accounts;

	/**
	 * 年龄
	 */
	@Column(name = "i_age", nullable = true)
	private Integer age;

	/**
	 * 性别
	 */
	@Column(name = "s_gender", length = 4, nullable = true)
	@DictionaryField(dictionaryName = "demo_gender", toFieldName = "genderName")
	private String gender;

	@Transient
	private String genderName;

	/**
	 * 学历
	 */
	@DictionaryField(dictionaryName = "demo_education", toFieldName = "educationName")
	@Column(name = "s_education", length = 30, nullable = true)
	private String education;

	@Transient
	private String educationName;

	@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
	@Column(name = "t_time", nullable = true)
	private Date time;

	/**
	 * 地址
	 */
	@Column(name = "s_address", length = 500, nullable = true)
	private String address;

	/**
	 * 是否有效
	 */
	@Column(name = "is_valid", nullable = true)
	private Boolean valid = null;

	@Column(name = "s_exeid", length = 50, nullable = true)
	private String exeid;

	@Column(name = "s_bpmstate", length = 50, nullable = true)
	private String bpmState;

	public String getAccounts() {
		return accounts;
	}

	public void setAccounts(String accounts) {
		this.accounts = accounts;
	}

	public Integer getAge() {
		return age;
	}

	public void setAge(Integer age) {
		this.age = age;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getGenderName() {
		return genderName;
	}

	public void setGenderName(String genderName) {
		this.genderName = genderName;
	}

	public String[] getEducation() {
		if (education == null) {
			return null;
		}
		return education.split(",");
	}

	public void setEducation(String[] education) {
		if (education == null) {
			this.education = null;
		} else {
			this.education = String.join(",", education);
		}
	}

	public String[] getEducationName() {
		if (educationName == null) {
			return null;
		}
		return educationName.split(",");
	}

	public void setEducationName(String[] educationName) {
		if (education == null) {
			this.educationName = null;
		} else {
			this.educationName = String.join(",", educationName);
		}
	}

	public Date getTime() {
		return time;
	}

	public void setTime(Date time) {
		this.time = time;
	}

	public List<FileMeta> getAddress() {
		if (address == null) {
			return null;
		}
		return JsonUtils.toBeanList(address, FileMeta.class);
	}

	public void setAddress(List<FileMeta> address) {
		if (address == null) {
			this.address = null;
		} else {
			this.address = JsonUtils.toJSONString(address);
		}
	}

	public Boolean getValid() {
		return valid;
	}

	public void setValid(Boolean valid) {
		this.valid = valid;
	}

	@Override
	public String getId() {
		return id;
	}

	@Override
	public void setId(String value) {
		id = value;
	}

	@Override
	public String getBpmState() {
		return bpmState;
	}

	@Override
	public String getExeid() {
		return exeid;
	}

	@Override
	@Transient
	public String getProName() {
		return accounts;
	}

	@Override
	public void setBpmState(String arg0) {
		bpmState = arg0;
	}

	@Override
	public void setExeid(String arg0) {
		exeid = arg0;
	}
}